<?php

$host = "localhost";
$user = "root";
$pass = "";
$db = "db_web";

$r = mysql_connect($host, $user, $pass);

if (!$r) {
  echo "Could not connect to server\n";
  trigger_error(mysql_error(), E_USER_ERROR);
} else {
  echo "Connection established\n";
}
$r2 = mysql_select_db($db);

if (!$r2) {
  echo "Cannot select database\n";
  trigger_error(mysql_error(), E_USER_ERROR);
} else {
  echo "Database selected\n";
}


$query = "CREATE TABLE IF NOT EXISTS Authors(Id INT PRIMARY KEY AUTO_INCREMENT, 
Name VARCHAR(25)) ENGINE=InnoDB";
mysql_query($query);


$name = "O'Neill";
$name_es = mysql_real_escape_string($name);

$query = "INSERT INTO Authors(Name) VALUE ('$name_es')";

$rs = mysql_query($query);

if (!$rs) {
  echo "Could not execute query: $query\n";
  trigger_error(mysql_error(), E_USER_ERROR);
} else {
  echo "Query: $query executed\n";
}

mysql_close();
?>